import Vue from 'vue'
import Router from 'vue-router'
import store from '../store/index.js'

import ljx from './routes/ljx';
import gjj from './routes/gjj';
import dhz from './routes/dhz';
import xyl from './routes/xyl';
import zj from './routes/zj';
import xzf from './routes/xzf';



Vue.use(Router)

let router =  new Router({
  routes: [
    ...ljx,
    ...dhz,
    ...gjj,
    ...xyl,
    ...xzf,
    ...zj
  ],
  mode:'history'
})

router.beforeEach((to,from,next) => {
	if(to.meta.requireAuth){
		let user = store.state.curLoginUser;
		if(user.phone !== undefined){
			next()
		}else{
			router.push({name:'login',params:{
				toPage:to
			}})
		}
	}else {
		next()
	}
})

export default router;